var vm = new Vue({
    el: '#contentContainer',
    data: {
        form: {
            processCategoryId: '',
            processCategoryKey: '',
            processCategoryName: ''
        },
        rules: {
            processCategoryKey: [
                {required: true, message: '请输入流程分类Key', trigger: 'blur'},
                {min: 0, max: 64, message: '长度不能超过64个字符', trigger: 'blur'}
            ],
            processCategoryName: [
                {required: true, message: '请输入流程分类名称', trigger: 'blur'},
                {min: 0, max: 64, message: '长度不能超过64个字符', trigger: 'blur'}
            ]
        }
    },
    created: function () {
        var $this = this;

        Common.getJson('/process/category/getProcessCategoryInfo',
            {processCategoryId: Common.getUrlParam('processCategoryId')},
            function (response) {
                if (!response || response.status != 200)
                    return;

                var categoryInfo = response.result;
                $this.form.processCategoryId = categoryInfo.processCategoryId;
                $this.form.processCategoryKey = categoryInfo.processCategoryKey;
                $this.form.processCategoryName = categoryInfo.processCategoryName;
            });
    },
    methods: {
        submitForm: function (formName) {
            var $this = this;

            $this.$refs[formName].validate(function (valid) {
                if (!valid)
                    return false;

                Common.postJson('/process/category/edit', $this.form,
                    function (response) {
                        if (!response)
                            return;

                        //保存成功
                        if (response.status == 200 && response.result.success)
                            window.location.href = '/process/category/list';
                        else {
                            var errMsg = response.status == 200 ? response.result.errMsg : response.msg;

                            $this.$notify.error({
                                title: '错误',
                                message: errMsg,
                                offset: $("#main", window.parent.document).height() - 120,
                                duration: 0
                            });
                        }
                    });
            });
        },
        resetForm: function (formName) {
            this.$refs[formName].resetFields();
        }
    }
});